<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            background-color: pink;
            margin: 200px;
        }
    </style>
</head>

<body>
    <div class="box" id="box"></div>
    <script>
       // 1.给box注册点击事件
       var box = document.querySelector('#box');
       box.onmousemove = function(e) {
        // 2.获取鼠标的坐标值 
        var pagex = e.pageX;
        var pagey = e.pageY;
        // 3.获取盒子的位置 offsetLeft  offsetTop
        var x = this.offsetLeft
        var y = this.offsetTop
        // 3.获取鼠标在盒子里面的坐标值  pagex - x 
        var boxPositionX = pagex - x;
        var boxPositionY = pagey - y;
        box.innerHTML = `x坐标为${boxPositionX} y坐标为 ${boxPositionY}`
       }
    </script>
</body>

</html>